﻿@model PagedList.IPagedList<TireStore.Models.Product>
@{
    ViewBag.Title = "Product";
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}
@using PagedList
@using PagedList.Mvc
@using TireStore.Helpers


<div id="Breadcrumb" class="Block Breadcrumb ui-widget-content ui-corner-top ui-corner-bottom">
    <ul>
        <li class='SecondLast'><a href='/admin'><i class="icon-home" style="font-size: 14px;"></i>Trang chủ</a></li>
        <li class='Last'><span>Danh sách sản phẩm</span></li>
    </ul>
</div>
<div style="clear: both;"></div>


<div id="cph_Main_ContentPane">
    <div class="widget">
        <div class="widget-title">
            <h4><i class="icon-list-alt"></i>&nbsp;Danh sách sản phẩm</h4>

            <div class="ui-widget-content ui-corner-top ui-corner-bottom">
                <div id="toolbox">

                    <div style="float: right;" class="toolbox-content">

                        <table class="toolbar">
                            <tr>

                                <td align="center">
                                    <a onclick="javascript:return PopupHelp(&#39;http://www.bizweb.vn/PopupHelp.aspx?faqcat=25&#39;);" id="cph_Main_ctl00_toolbox_rptAction_lbtAction_0" title="Trợ giúp" class="toolbar btn btn-info" href="javascript:__doPostBack(&#39;ctl00$cph_Main$ctl00$toolbox$rptAction$ctl01$lbtAction&#39;,&#39;&#39;)"><i class="icon-question-sign"></i>&nbsp;
                            Trợ giúp</a>
                                </td>

                                <td align="center">
                                    <a id="cph_Main_ctl00_toolbox_rptAction_lbtAction_1" title="Thêm mới" class="toolbar btn btn-info" href="../Product/Create"><i class="icon-plus"></i>&nbsp;
                            Thêm mới</a>
                                </td>

                                <td align="center">
                                    <a id="cph_Main_ctl00_toolbox_rptAction_lbtAction_2" title="Cập nhật giá" class="toolbar btn btn-info" href="javascript:__doPostBack(&#39;ctl00$cph_Main$ctl00$toolbox$rptAction$ctl03$lbtAction&#39;,&#39;&#39;)"><i class="icon-ok"></i>&nbsp;
                            Cập nhật giá</a>
                                </td>

                                <td align="center">
                                    <a onclick="javascript:return ConfirmDelete();" id="cph_Main_ctl00_toolbox_rptAction_lbtAction_3" title="Xóa" class="toolbar btn btn-info" href="javascript:__doPostBack(&#39;ctl00$cph_Main$ctl00$toolbox$rptAction$ctl04$lbtAction&#39;,&#39;&#39;)"><i class="icon-trash"></i>&nbsp;
                            Xóa</a>
                                </td>

                            </tr>
                        </table>

                    </div>
                </div>
            </div>
            <div id="hiddenToolBarScroll" class="scrollBox hidden">
                <h4>
                    <i class="icon-list-alt"></i>&nbsp;Danh sách sản phẩm</h4>
                <div class="FloatMenuBar">

                    <div class="ui-widget-content ui-corner-top ui-corner-bottom">
                        <div id="Div1">

                            <div style="float: right;" class="toolbox-content">

                                <table class="toolbar">
                                    <tr>

                                        <td align="center">
                                            <a onclick="javascript:return PopupHelp(&#39;http://www.bizweb.vn/PopupHelp.aspx?faqcat=25&#39;);" id="cph_Main_ctl00_toolbox2_rptAction_lbtAction_0" title="Trợ giúp" class="toolbar btn btn-info" href="javascript:__doPostBack(&#39;ctl00$cph_Main$ctl00$toolbox2$rptAction$ctl01$lbtAction&#39;,&#39;&#39;)"><i class="icon-question-sign"></i>&nbsp;
                            Trợ giúp</a>
                                        </td>

                                        <td align="center">
                                            <a id="cph_Main_ctl00_toolbox2_rptAction_lbtAction_1" title="Thêm mới" class="toolbar btn btn-info" href="../Product/Create"><i class="icon-plus"></i>&nbsp;
                            Thêm mới</a>
                                        </td>

                                        <td align="center">
                                            <a id="cph_Main_ctl00_toolbox2_rptAction_lbtAction_2" title="Cập nhật giá" class="toolbar btn btn-info" href="javascript:__doPostBack(&#39;ctl00$cph_Main$ctl00$toolbox2$rptAction$ctl03$lbtAction&#39;,&#39;&#39;)"><i class="icon-ok"></i>&nbsp;
                            Cập nhật giá</a>
                                        </td>

                                        <td align="center">
                                            <a onclick="javascript:return ConfirmDelete();" id="cph_Main_ctl00_toolbox2_rptAction_lbtAction_3" title="Xóa" class="toolbar btn btn-info" href="javascript:__doPostBack(&#39;ctl00$cph_Main$ctl00$toolbox2$rptAction$ctl04$lbtAction&#39;,&#39;&#39;)"><i class="icon-trash"></i>&nbsp;
                            Xóa</a>
                                        </td>

                                    </tr>
                                </table>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="widget-body">




            <script type="text/javascript">
                function SelectAllCheckboxes(chk) {
                    $j('#cph_Main_ctl00_ctl00_grvProducts >tbody >tr >td:nth-child(1)').find("input:checkbox").attr('checked', chk.checked);
                }

                function ShowQuickHelp(container, title, desc) {
                    var div = document.createElement("div");
                    div.id = 'help';
                    div.style.zIndex = 1;
                    div.style.display = 'block';
                    div.style.position = 'absolute';
                    div.style.width = '185px';
                    div.style.backgroundColor = '#FEFCD5';
                    div.style.border = 'solid 1px #E7E3BE';
                    div.style.padding = '10px';
                    if (title != '') {
                        div.innerHTML = '<div class="helpTip"><strong>' + title + '</strong></div><br />';
                    }
                    div.innerHTML += '<div style="width:185px; padding-left:0px" class=helpTip>' + desc + '</div>';
                    SetQuickHelpPosition(div, container, 185)
                    container.parentNode.appendChild(div);
                }
                function SetQuickHelpPosition(d, container, width) {
                    var containerX = 0;
                    var containerY = 0;
                    var containerTemp = container;
                    while (containerTemp != null) {
                        containerX += containerTemp.offsetLeft;
                        containerY += containerTemp.offsetTop;
                        containerTemp = containerTemp.offsetParent;
                    }
                    var scrollXY = getScrollXY();
                    var windowRight = document.documentElement.clientWidth;
                    var divX = windowRight - width;
                    var divY = containerY + 15;
                    if (divX <= containerX - scrollXY[0]) {
                        d.style.left = divX + 'px';
                    }
                    else if (width + containerX + 50 > $j(window).width()) {
                        d.style.left = (divX - width - 50) + 'px';
                    }
                    d.style.top = divY + 'px';
                }
                function getScrollXY() {
                    var scrOfX = 0, scrOfY = 0;
                    if (typeof (window.pageYOffset) == 'number') {
                        //Netscape compliant
                        scrOfY = window.pageYOffset;
                        scrOfX = window.pageXOffset;
                    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
                        //DOM compliant
                        scrOfY = document.body.scrollTop;
                        scrOfX = document.body.scrollLeft;
                    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
                        //IE6 standards compliant mode
                        scrOfY = document.documentElement.scrollTop;
                        scrOfX = document.documentElement.scrollLeft;
                    }
                    return [scrOfX, scrOfY];
                }
                function HideQuickHelp(p) {
                    if ($j("#help").length) {
                        $j("#help").css('display', 'none');
                        setTimeout('RemoveHelp()', 1);
                    }
                }
                function RemoveHelp() {
                    $j("#help").remove();
                }
                function ConvertPrice(numberText, culture) {
                    if (numberText == "") return 0;
                    if (culture == "vi-VN") {
                        numberText = numberText.replace(/\./g, "");
                    }
                    else {
                        var s = numberText.length - 2;
                        var c = numberText.substring(s - 1, s);
                        if (c == ".") {
                            numberText = numberText.replace(/\,/g, "");
                        }
                        if (c == ",") {
                            numberText = numberText.replace(/\./g, "");
                            numberText = numberText.replace(/\,/g, ".");
                        }
                    }
                    numberText = numberText.replace(/ /g, '');
                    numberText = encodeURIComponent(numberText);
                    numberText = numberText.replace(/%C2%A0/g, '');
                    numberText = decodeURIComponent(numberText);
                    return Number(numberText);
                }
                function UpdateProduct(linkUpdateId, pId) {
                    var id = $j(linkUpdateId).closest('tr').children(".Id").children("#txtId").val();
                    var code = $j(linkUpdateId).closest('tr').children(".Code").children("#txtCode").val();
                    var price = $j(linkUpdateId).closest('tr').children(".Price").children("#txtPrice").val();
                    var retailPrice = $j(linkUpdateId).closest('tr').children(".RetailPrice").children("#txtRetailPrice").val();
                    var salePrice = $j(linkUpdateId).closest('tr').children(".SalePrice").children("#txtSalePrice").val();
                    var orderNumber = $j(linkUpdateId).closest('tr').children(".OrderNumber").children("#txtOrderNumber").val();
                    var status = $j(linkUpdateId).closest('tr').children(".Status").children("#ddlStatus").val();
                    var isVisible;
                    if ($j('#lbChangeVisible' + pId).children('i').attr('class') == 'icon-eye-open') {
                        isVisible = 'true';
                    }
                    else {
                        isVisible = 'false';
                    }

                    if (price < salePrice) { alert("Giá khuyến mãi phải nhỏ hơn giá bán !"); return false; }

                    var querystring = "{'productid':'" + id + "'," +
                        "'price':'" + price + "'," +
                        "'retailprice':'" + retailPrice + "'," +
                        "'saleprice':'" + salePrice + "'," +
                        "'ordernumber':'" + orderNumber + "'," +
                        "'isvisible':'" + isVisible + "'," +
                        "'code':'" + code + "'," +
                        "'status':'" + status + "'" + "}";

                    $j.ajax({
                        beforeSend: function () { },
                        type: "POST",
                        url: "/WebServices/ProductService.asmx/UpdateProduct",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        data: querystring,
                        success: function (response) {
                            var result = response.d;
                            if (result == "true") alert("Cập nhật thông tin sản phẩm thành công !");
                            else { if (result != "false") alert(result); }
                        }
                    });

                    return false;

                }

                function ChangeVisibleProduct(lnk) {
                    var st = $j(lnk).attr('st');
                    var isvisible = 'true';
                    if (st == 'open') { isvisible = 'false'; }
                    else { isvisible = 'true'; }

                    var productId = $j(lnk).attr('productid');

                    var linkUpdateId = $j("#lbtUpdateProduct" + productId);
                    var id = $j(linkUpdateId).closest('tr').children(".Id").children("#txtId").val();
                    var code = $j(linkUpdateId).closest('tr').children(".Code").children("#txtCode").val();
                    var price = $j(linkUpdateId).closest('tr').children(".Price").children("#txtPrice").val();
                    var retailprice = 0;
                    var salePrice = $j(linkUpdateId).closest('tr').children(".SalePrice").children("#txtSalePrice").val();
                    var orderNumber = $j(linkUpdateId).closest('tr').children(".OrderNumber").children("#txtOrderNumber").val();
                    var status = $j(linkUpdateId).closest('tr').children(".Status").children("#ddlStatus").val();
                    var culture = $j(linkUpdateId).closest('tr').children(".Price").children("#txtPrice").attr("culture");

                    price = ConvertPrice(price, culture);
                    salePrice = ConvertPrice(salePrice, culture);

                    if (price < salePrice) { alert("Giá khuyến mãi phải nhỏ hơn giá bán !"); return false; }
                    return false;
                }
            </script>
            
            <div class="row-fluid">
                <div class="span3">
                    <div id="sample_1_length" class="dataTables_length">
                        @Html.DropDownList("PageNumber", TsSelectList.GetPageNumber())
                    </div>
                </div>
                <div class="span9 form-search pull-right text-right">
                    <input name="txtSearch" type="text" maxlength="100" id="txtSearch" placeholder="Tên sản phẩm" style="width: 200px;" />
                    @Html.DropDownList("dllProductGroup", TsSelectList.GetProductGroup(), new { style = "width: 160px;" })
                    <input type="submit" name="btnSearch" value="Tìm kiếm" id="btnSearch" class="btn" />
                </div>
            </div>
            <div id="grvProduct">
            @Html.Partial("_partialProductGrid", Model)
                </div>
            <style type="text/css">
                #tooltip {
                    position: absolute;
                    z-index: 10102;
                    background-color: #FFF;
                    padding: 5px;
                    border: solid 3px #cccccc;
                    display: block;
                    width: 350px;
                    text-align: center;
                }
            </style>
            <script type="text/javascript" src="http://media.bizwebmedia.net/Extensions/Js/jquery.tooltip.min.js"></script>
            <div id="productImagePopup" class="hidden"></div>
            <script type="text/ecmascript">
                $j(function () {
                    $j('.thumb-image img').each(function () {
                        $j(this).bind('mouseover', function () {
                            var respText =
                                    "<img src=\"" + $j(this).attr("thumbnail") + "\" onerror=\"this.src='" + $j(this).attr("thumbnail-error") + "'\" alt=\"" + $j(this).attr("product-name") + "\" />";
                            $j('#productImagePopup').html(respText);
                        });
                        $j(this).tooltip({
                            track: true, delay: 50, showURL: false,
                            bodyHandler: function () {
                                return $j('#productImagePopup').html();
                            }
                        });
                    });
                });


            </script>
            <script type="text/javascript">
                function deleteProduct(productId) {
                    //alert(productId);
                    $j.ajax({
                        type: "GET",
                        url: '/Product/Index?productId=' + productId + "&funcName=1",
                        contentType: "application/json; charset=utf-8",
                        dataType: "JSON",
                        success: function(res) {
                            alert(res);
                        }
                    });
                };
            </script>
        </div>
    </div>
</div>
